1 using System;
2 using
System.Collections.Generic;
3 using
System.ComponentModel;
4 using
System.Data;
5 using
System.Drawing;
6 using
System.Text;
7 using
System.Data.SqlClient;
8 using
System.Windows.Forms;
9 using
Telerik.WinControls.UI;
10 using
Telerik.WinControls.UI.Scheduler.Dialogs;
11 using
Telerik.WinControls;
12 using
Telerik.WinControls.Themes;
13 //
using Telerik.Examples.WinControls.DataSources.SchedulerDataSetTableAdapters;
14 //
using Telerik.Examples.WinControls.DataSources;
15 using
QuanLyNhanSu.SchedulerDatasetTableAdapters;
16 using
Telerik.WinControls.Enumerations;
17 using
QuanLyNhanSu.Class;
18 namespace
QuanLyNhanSu
19 {
20     
public partial class frmLichLamViec : RadForm
21     {
22
23         sql sql =
new sql();
24
25         
private SchedulerDataset schedulerDataSet = null;
26         
public frmLichLamViec()
27         {
28             
29             
//SqlConnection con = frmMain.me.sql.connectSQL();
30             
//con.Open();
31             
//SqlCommand
32             
//con.Close();
33             InitializeComponent();
34             
this.radSchedulerDemo.GetDayView().DayCount = 1;
35             
this.radSchedulerNavigator1.ShowWeekendStateChanged += new StateChangedEventHandler(radSchedulerNavigator1_ShowWeekendStateChanged);
36             
this.radCalendar1.ShowOtherMonthsDays = false;
37             
this.radCalendar1.AllowMultipleSelect = false;
38             
this.radCalendar1.TitleFormat = "MMMM";
39             
40             
this.radCalendar1.SelectedDate = DateTime.Today;
41             
this.radCalendar1.SelectionChanged += new EventHandler(radCalendar1_SelectionChanged);
42             
//this.cmbTheme.SelectedIndexChanged += new EventHandler(cmbTheme_SelectedIndexChanged);
43             
this.Load += new EventHandler(Form1_Load);
44             
this.radSchedulerDemo.PropertyChanged += new PropertyChangedEventHandler(radScheduler1_PropertyChanged);
45             
this.radSchedulerDemo.Appointments.CollectionChanged += new Telerik.WinControls.Data.NotifyCollectionChangedEventHandler(Appointments_CollectionChanged);
46         }
47
48         
49         
50         
void Form1_Load(object sender, EventArgs e)
51         {
52             
this.radCalendar1.InvalidateCalendar();
53             BindToDataSet();
54         }
55
56
57         
private void BindToDataSet()
58         {
59             
if (this.schedulerDataSet == null)
60             {
61                 
this.schedulerDataSet = new SchedulerDataset();
62
63                 AppointmentsTableAdapter appointmentsAdapter =
new AppointmentsTableAdapter();
64                 appointmentsAdapter.Fill(
this.schedulerDataSet.Appointments);
65
66                 ResourcesTableAdapter resourcesAdapter =
new ResourcesTableAdapter();
67                 resourcesAdapter.Fill(
this.schedulerDataSet.Resources);
68
69                 TransientAppointmentsResourcesTableAdapter appointmentsResourcesAdapter =
new TransientAppointmentsResourcesTableAdapter();
70                 appointmentsResourcesAdapter.Fill(
this.schedulerDataSet.TransientAppointmentsResources);
71             }
72
73             SchedulerBindingDataSource dataSource =
new SchedulerBindingDataSource();
74             AppointmentMappingInfo appointmentMappingInfo =
new AppointmentMappingInfo();
75             appointmentMappingInfo.Start =
"Start";
76             appointmentMappingInfo.End =
"End";
77             appointmentMappingInfo.Summary =
"Summary";
78             appointmentMappingInfo.Description =
"Description";
79             appointmentMappingInfo.Location =
"Location";
80             appointmentMappingInfo.BackgroundId =
"BackgroundID";
81             appointmentMappingInfo.StatusId =
"StatusID";
82             appointmentMappingInfo.Resources =
"Appointments_AppointmentsResources";
83             appointmentMappingInfo.ResourceId =
"ResourceID";
84             appointmentMappingInfo.RecurrenceRule =
"RecurrenceRule";
85
86             dataSource.EventProvider.Mapping = appointmentMappingInfo;
87             dataSource.EventProvider.DataSource =
this.schedulerDataSet.Appointments;
88
89             ResourceMappingInfo resourceMappingInfo =
new ResourceMappingInfo();
90             resourceMappingInfo.Id =
"ID";
91             resourceMappingInfo.Name =
"ResourceName";
92
93             dataSource.ResourceProvider.Mapping = resourceMappingInfo;
94             dataSource.ResourceProvider.DataSource =
this.schedulerDataSet.Resources;
95
96             
this.radSchedulerDemo.DataSource = dataSource;
97         }
98
99         
protected override void OnLoad(EventArgs e)
100         {
101             
base.OnLoad(e);
102             
this.radSchedulerNavigator1.ThemeName = "ControlDefault";
103
104             
//DateTime baseDate = DateTime.Today;
105             
//DateTime[] start = new DateTime[] { baseDate.AddHours(14.0), baseDate.AddDays(1.0).AddHours(9.0), baseDate.AddDays(2.0).AddHours(13.0) };
106             
//DateTime[] end = new DateTime[] { baseDate.AddHours(16.0), baseDate.AddDays(1.0).AddHours(15.0), baseDate.AddDays(2.0).AddHours(17.0) };
107             
//string[] summaries = new string[] { "Mr. Brown", "Mr. White", "Mrs. Green" };
108             
//string[] descriptions = new string[] { "", "", "" };
109             
//string[] locations = new string[] { "City", "Out of town", "Service Center" };
110             
//AppointmentBackground[] backgrounds = new AppointmentBackground[] { AppointmentBackground.Business, AppointmentBackground.MustAttend, AppointmentBackground.Personal };
111
112             
//this.radSchedulerDemo.Appointments.BeginUpdate();
113             
//Appointment appointment = null;
114             
//for(int i = 0; i < summaries.Length; i++)
115             
//{
116             
// appointment = new Appointment(start[i], end[i], summaries[i],
117             
// descriptions[i], locations[i]);
118             
// appointment.Background = backgrounds[i];
119             
// this.radSchedulerDemo.Appointments.Add(appointment);
120             
//}
121
122             
//appointment = new Appointment(baseDate.AddHours(11.0), baseDate.AddHours(12.0), "Wash the car", "", "Garage");
123             
//appointment.RecurrenceRule = new DailyRecurrenceRule(baseDate.AddHours(11.0), 2);
124             
//this.radSchedulerDemo.Appointments.Add(appointment);
125             
//this.radSchedulerDemo.Appointments.EndUpdate();
126             
this.radSchedulerDemo.Resources.Clear();
127             
this.radSchedulerDemo.Resources.Add(new Resource(1, "Dell Laptop"));
128             
this.radSchedulerDemo.Resources.Add(new Resource(2, "Lenovo Laptop"));
129             
this.radSchedulerDemo.Resources.Add(new Resource(3, "Toshiba Laptop"));
130
131             
this.InitializeCalendar();
132
133             (
this.radSchedulerDemo.ActiveView as SchedulerDayViewBase).RangeFactor = ScaleRange.HalfHour;
134             (
this.radSchedulerDemo.SchedulerElement.ViewElement as SchedulerDayViewElement).DataAreaElement.ScrollView.Value = Point.Empty;
135
136             
for (int i = 0; i < 16; i++)
137             {
138                 (
this.radSchedulerDemo.SchedulerElement.ViewElement as SchedulerDayViewElement).DataAreaElement.Table.Scroll(false);
139             }
140
141             
this.radSchedulerDemo.ActiveViewChanged += new EventHandler<SchedulerViewChangedEventArgs>(radSchedulerDemo_ActiveViewChanged);
142         }
143
144         
void radSchedulerDemo_ActiveViewChanged(object sender, SchedulerViewChangedEventArgs e)
145         {
146             
if (e.NewView as SchedulerMonthView == null)
147             {
148                 (
this.radSchedulerDemo.ActiveView as SchedulerDayViewBase).RangeFactor = ScaleRange.HalfHour;
149                 (
this.radSchedulerDemo.SchedulerElement.ViewElement as SchedulerDayViewElement).DataAreaElement.ScrollView.Value = Point.Empty;
150
151                 
for (int i = 0; i < 16; i++)
152                 {
153                     (
this.radSchedulerDemo.SchedulerElement.ViewElement as SchedulerDayViewElement).DataAreaElement.Table.Scroll(false);
154                 }
155
156             }
157         }
158
159         
void Appointments_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
160         {
161
162             InitializeCalendar();
163             SaveChanges();
164             
//MessageBox.Show("change");
165             
//try
166             
//{
167             
// for (int i = 0; i < e.NewItems.Count; i++)
168             
// {
169                     
170             
// MessageBox.Show(e.PropertyName);
171             
// MessageBox.Show(e.NewItems[i].ToString());
172             
// }
173             
//}
174             
//catch
175             
//{
176             
//}
177
178         }
179
180         
private void InitializeCalendar()
181         {
182             MultiMonthViewElement viewElement =
this.radCalendar1.CalendarElement.CalendarVisualElement as MultiMonthViewElement;
183
184             
if (viewElement != null)
185             {
186                 CalendarMultiMonthViewTableElement table = viewElement.GetMultiTableElement();
187                 
188                 
foreach (MonthViewElement monthView in table.Children)
189                 {
190
191                     
foreach (CalendarCellElement cell in monthView.TableElement.Children)
192                     {
193
194                         
bool headerCell = (bool)cell.GetValue(CalendarCellElement.IsHeaderCellProperty);
195                         
if (headerCell)
196                             
continue;
197
198                         SchedulerDayView view =
new SchedulerDayView();
199                         view.DayCount =
1;
200                         view.StartDate = cell.Date;
201                         view.GetViewContainingDate(cell.Date);
202
203                         view.UpdateAppointments(
this.radSchedulerDemo.Appointments);
204
205
206                         
if (view.Appointments.Count > 0)
207                         {
208                             cell.Font =
new Font(cell.Font, FontStyle.Bold);
209                         }
210                         
else
211                         {
212                             cell.Font =
this.radCalendar1.Font;
213                         }
214                     }
215                 }
216             }
217         }
218
219         
void radScheduler1_PropertyChanged(object sender, PropertyChangedEventArgs e)
220         {
221             InitializeCalendar();
222         }
223
224
225         
void radCalendar1_SelectionChanged(object sender, EventArgs e)
226         {
227             
this.radSchedulerDemo.ActiveView.StartDate = this.radCalendar1.SelectedDate;
228         }
229
230         
private void radSchedulerNavigator1_ShowWeekendStateChanged(object sender, StateChangedEventArgs args)
231         {
232             
if (this.radSchedulerDemo.ActiveView as SchedulerMonthView == null)
233             {
234                 (
this.radSchedulerDemo.ActiveView as SchedulerDayViewBase).RangeFactor = ScaleRange.HalfHour;
235                 (
this.radSchedulerDemo.SchedulerElement.ViewElement as SchedulerDayViewElement).DataAreaElement.ScrollView.Value = Point.Empty;
236
237                 
for (int i = 0; i < 16; i++)
238                 {
239                     (
this.radSchedulerDemo.SchedulerElement.ViewElement as SchedulerDayViewElement).DataAreaElement.Table.Scroll(false);
240                 }
241             }
242         }
243         
private void radSchedulerDemo_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
244         {
245             RadForm form = e.AppointmentEditDialog
as RadForm;
246             form.FormClosing +=
new FormClosingEventHandler(form_FormClosing);
247             
248             
if (e.Appointment.Summary == "")
249             {
250                 e.Appointment.End = DateTime.Now;
251                 e.Appointment.Start = DateTime.Now;
252
253             }
254
255         }
256
257         
void form_FormClosing(object sender, FormClosingEventArgs e)
258         {
259             
//throw new NotImplementedException();
260             RadForm form = sender
as RadForm;
261             DialogResult result = (sender
as RadForm).DialogResult;
262             
if(result==DialogResult.OK)
263             {
264                 
if (form.Controls["txtSubject"].Text == "")
265                 {
266                     RadMessageBox.Show(
"\nSubject không được rỗng !\n", "Thông báo", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
267                     e.Cancel =
true;
268                 }
269             }
270
271             
272            
273         }
274         
private void SaveChanges()
275         {
276             AppointmentsTableAdapter appointmentsAdapter =
new AppointmentsTableAdapter();
277             appointmentsAdapter.Update(
this.schedulerDataSet.Appointments);
278
279             TransientAppointmentsResourcesTableAdapter appointmentsResourcesAdapter =
new TransientAppointmentsResourcesTableAdapter();
280             appointmentsResourcesAdapter.Update(
this.schedulerDataSet.TransientAppointmentsResources);
281         }
282
283
284
285         
286
287
288     }
289 }



Quản lý nhân sự công ty bằng c# _ full source code 60.427 lượt xem

Gõ tìm kiếm nhanh...